<?php
require "../modules/conn.php";
	session_start();
	$keyword=isset($_SESSION["keyword"])?$_SESSION["keyword"]:"";

	// 每页多少条
	$pagesize=3;
	// 当前显示第几页
	$pageNo = empty($_REQUEST["pageNo"])?1:$_REQUEST["pageNo"];

	// 总共分多少页
	$sql1 = "select ceil(count(sid)/".$pagesize.") from t_sell s where title like '%$keyword%'";
	$result1 = mysqli_query($conn, $sql1);
	if($result1){
		if($row = mysqli_fetch_row($result1)){
			$pageTotal = $row[0];
		}
	}else{
		echo $pageNo;
	}


	$sql="select s.sid,s.title,s.price,s.curr,s.payment,i.imgid from t_sell s,t_image i where title like '%$keyword%' and s.sid=i.s_img_id group by s.sid limit ".($pageNo-1)*$pagesize.", ".$pagesize;

	$result=mysqli_query($conn,$sql);
	if($result){
		$arr=array();
		while($row=mysqli_fetch_assoc($result)){
			
			array_push($arr,$row);
		}
		array_push($arr,$pageTotal);
		echo json_encode($arr);
		// echo $sql;
	}else{
		echo $sql;
	}
?>